#include "mpu6050.h"
Adafruit_MPU6050 mpu;
void mpu6050_Init() {
    if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
        while (1) {
            delay(10);
        }
    }
    Serial.println("MPU6050 Found!");
    // 设置传感器参数
    mpu.setAccelerometerRange(MPU6050_RANGE_8_G);  // 或 MPU6050_RANGE_16_G
    mpu.setFilterBandwidth(MPU6050_BAND_260_HZ);   // 带宽最大，延迟最小
    mpu.setGyroRange(MPU6050_RANGE_500_DEG);       // 可选
}

MpuData mpu6050_GetData() {
    MpuData data;
    sensors_event_t a, g, temp;
    mpu.getEvent(&a, &g, &temp);
    data.ax = a.acceleration.x;
    data.ay = a.acceleration.y;
    data.az = a.acceleration.z;
    data.gx = g.gyro.x;
    data.gy = g.gyro.y;
    data.gz = g.gyro.z;
    return data;
}
